'use client'

import React from 'react'
import { AntdRegistry } from '@ant-design/nextjs-registry'
import { ConfigProvider, App } from 'antd'
import zhCN from 'antd/locale/zh_CN'
import { StoreProvider } from '@/providers/StoreProvider'
import { ErrorBoundary } from '@/components/ErrorBoundary'
import { NavigationProvider } from '@/components/NavigationProvider'
import { ThemeProvider as EnhancedThemeProvider } from '@/components/ThemeProvider'
import {
    NotificationContainer,
    AutoLoadingManager,
    ConfirmationManager
} from '@/components/Feedback'
import { DevToolsToggle } from '@/components/DevTools/DevToolsToggle'

// 内部Providers组件（在StoreProvider内部）
const InnerProviders: React.FC<{ children: React.ReactNode }> = ({ children }) => {
    return (
        <NavigationProvider>
            <EnhancedThemeProvider>
                <ConfigProvider locale={zhCN}>
                    <App>
                        <AutoLoadingManager>
                            {children}
                        </AutoLoadingManager>

                        {/* 反馈系统组件 */}
                        <NotificationContainer />
                        <ConfirmationManager />

                        {/* 开发工具 */}
                        <DevToolsToggle />
                    </App>
                </ConfigProvider>
            </EnhancedThemeProvider>
        </NavigationProvider>
    )
}

// 主要的Providers组件
export const Providers: React.FC<{ children: React.ReactNode }> = ({ children }) => {
    return (
        <ErrorBoundary>
            <AntdRegistry>
                <StoreProvider>
                    <InnerProviders>
                        {children}
                    </InnerProviders>
                </StoreProvider>
            </AntdRegistry>
        </ErrorBoundary>
    )
}

export default Providers